﻿using LSL.SqlClient;
using System.Text;

namespace Liu_Project.Dal.Common
{
    public static class RoleHelper
    {
        /// <summary>获取菜单权限</summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public static string GetRoleMenu(long UserId, SQLHelper sqlHelper)
        {
            string tbTemp = sqlHelper.GetTempTable();

            StringBuilder sbSql = new StringBuilder();
            sbSql.Length = 0;
            sbSql.AppendLine("SELECT MenuId,SUM([Value]) SumValue");
            sbSql.AppendLine("INTO [" + tbTemp + "]");
            sbSql.AppendLine("FROM EntOwnerMenuCapability");
            sbSql.AppendLine("WHERE ((OwnerType='R' AND OwnerId IN (SELECT RoleId FROM EntRoleUser WHERE UserId='" + UserId + "') )");
            sbSql.AppendLine("OR (OwnerType='U' AND OwnerId='" + UserId + "'))");
            sbSql.AppendLine("GROUP BY MenuId");
            sbSql.AppendLine("HAVING SUM([Value]) > 0");
            //sbSql.AppendLine("DELETE FROM " + tbTemp + " WHERE SumValue <= 0 ");
            sqlHelper.ExecuteNonQuery(sbSql.ToString());

            return tbTemp;
        }
    }
}
